<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8"/>
    <title>学业表现测评</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta content="A fully featured admin theme which can be used to build CRM, CMS, etc." name="description"/>
    <meta content="Coderthemes" name="author"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <!-- App favicon -->
    <link rel="shortcut icon" href="./assets/images/favicon.ico">

    <!-- App css -->
    <link href="./css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
    <link href="./css/icons.min.css" rel="stylesheet" type="text/css"/>
    <link href="./css/app.css" rel="stylesheet" type="text/css"/>

</head>

<body>

<!-- Begin page -->
<div id="wrapper">

    <!-- ========== Left Sidebar Start ========== -->
    <div th:replace="commons/sideBar :: sidebar"/>
    <!-- Left Sidebar End -->


    <div class="content-page">
        <div class="content">

            <!-- Topbar Start -->
            <div th:replace="commons/topBar :: topbar "/>
            <!-- end Topbar -->

            <!-- Start Content-->
            <div class="container-fluid">

                <!-- start page title -->
                <div class="row">
                    <div class="col-12">
                        <div class="page-title-box">
                            <div class="page-title-right">
                                <ol class="breadcrumb m-0">
                                    <li class="breadcrumb-item"><a href="#">首页</a></li>
                                    <li class="breadcrumb-item active">学业表现测评</li>
                                </ol>
                            </div>
                            <h4 class="page-title">学业表现测评（折算分70%）</h4>
                        </div>
                    </div>
                </div>
                <!-- end page title -->
            </div>


            <!-- ============================================================== -->
            <!-- Start Page Content here -->
            <!-- ============================================================== -->
            <div class="" style="width: 500px; height: 400px">
                <div class="card-body" style="padding-top: 0px;">
                    <h4 class="mb-3 header-title">测评内容：</h4>

                    <form class="form-horizontal" id="academicForm">

                        <div class="form-group row mb-3">
                            <label for="bastScore" class="col-3 col-form-label">基本分：</label>
                            <div class="col-9" th:if="${academic.status != '0'}">
                                <input class="form-control" name="basicPoints" disabled th:value="${academic.basicPoints}" id="bastScore" placeholder="">
                            </div>
                            <div class="col-9" th:if="${academic.status == '0'}">
                                <input class="form-control" name="basicPoints" th:value="${academic.basicPoints}" id="bastScore" placeholder="">
                            </div>
                        </div>

                        <div class="form-group row mb-3">
                            <label for="failedNum" class="col-3 col-form-label">挂科门数：</label>
                            <div class="col-9" th:if="${academic.status!='0'}">
                                <input type="number" class="form-control" disabled name="failedNum" th:value="${academic.failedNum}" id="failedNum"
                                       placeholder="">
                            </div>
                            <div class="col-9" th:if="${academic.status=='0'}">
                                <input type="number" class="form-control" name="failedNum" th:value="${academic.failedNum}" id="failedNum"
                                       placeholder="">
                            </div>
                        </div>

                        <div class="form-group row mb-3">
                            <label for="score" class="col-3 col-form-label">预计得分：</label>
                            <div class="col-9">
                                <input class="form-control" id="score" disabled  th:value="${academic.subtotal}"
                                        placeholder="学业分总分（基本分减去扣分）">
                                <input class="form-control" id="hidden_score" type="hidden"  name="subtotal" th:value="${academic.subtotal}"
                                       >
                            </div>
                        </div>

                        <div class="form-group row mb-3">
                            <label for="score" class="col-3 col-form-label">当前状态：</label>
                            <div class="col-9">

                                <span class="badge badge-secondary badge-pill notSub" style="margin-top: 10px" th:if="${academic.status=='0'}">未提交</span>
                                <span class="badge  badge-info badge-pill notSub" style="margin-top: 10px" th:if="${academic.status=='1'}">待审核</span>
                                <span class="badge badge-success badge-pill notSub " style="margin-top: 10px" th:if="${academic.status=='2'}">审核通过</span>
                                <span class="badge badge-danger badge-pill notSub " style="margin-top: 10px" th:if="${academic.status=='3'}">待修改</span>

                                <input type="hidden" name="status" value="1">
                                <input type="hidden" name="stuId" th:value="${session.loginStu.stuId}">
                            </div>
                        </div>
                        <div class="form-group row mb-3" th:if="${academic.msg != null && academic.status != '2' && academic.status != '1'}" id="msg">
                            <label for="score" class="col-3 col-form-label" style="color: red">驳回原因：</label>
                            <div class="col-9"  style="padding-top: 8px">
                                <span th:text="${academic.msg}"></span>
                            </div>
                        </div>
                        <div class="form-group mb-0 justify-content-end row">
                            <div class="col-9">
                                <button id="submitForm" class="btn btn-info" th:if="${academic.status=='0'}" >提交</button>
                                <button id="submitForm" class="btn btn-info" disabled th:if="${academic.status!='0'}">提交</button>
                                <button class="btn btn-danger reEdit" disabled th:if="${academic.status=='0'}">重新编辑</button>
                                <button class="btn btn-danger reEdit" disabled th:if="${academic.status=='2'}">重新编辑</button>
                                <button class="btn btn-danger reEdit"  th:if="${academic.status!='0' && academic.status !='2'}">重新编辑</button>
                            </div>
                        </div>

                    </form>

                </div>
            </div>
        </div>
    </div>
    <!-- ============================================================== -->
    <!-- End Page content -->
    <!-- ============================================================== -->
</div>


<!-- Footer Start -->
<div th:replace="commons/footer :: foot"></div>
<!-- end Footer -->


<!-- App js -->
<script src="./js/vendor.js"></script>
<script src="./js/app.js"></script>

<!-- Plugins js -->
<script src="./js/vendor/Chart.bundle.js"></script>
<script src="./js/vendor/jquery.sparkline.min.js"></script>
<script src="./js/vendor/jquery.knob.min.js"></script>
<script src="./js/jquery-2.1.1.min.js"></script>
<script src="./js/layer/layer.js"></script>

<script src="./js/pages/dashboard.init.js"></script>

<script>
    $("#failedNum").bind('input propertychange', function () {
        var failNum = $(this).val();
        var basePoint = $("#bastScore").val();
        if ("" === basePoint) {
            $(this).val("");
            layer.msg('请先输入学业基本分！');
            return;
        }
        var countScore =((basePoint - failNum) * 0.7).toFixed(2) < 0 ? "0" : ((basePoint - failNum) * 0.7).toFixed(2);
        $("#score").val(countScore);
        $("#hidden_score").val(countScore);
    });

    $("#bastScore").bind('input propertychange', function () {
        var basePoint = $(this).val();
        if (isNaN(basePoint)) {
            $(this).val("");
            layer.msg('基本分仅为数字！');
        }
        if ("" === basePoint) {
            $("#failedNum").val("");
            $("#score").val("");
            return;
        }
        var failNum = $("#failedNum").val();
        if ("" === failNum) {
            return;
        }
        var countScore =((basePoint - failNum) * 0.7).toFixed(2) < 0 ? "0" : ((basePoint - failNum) * 0.7).toFixed(2);
        $("#score").val(countScore);
        $("#hidden_score").val(countScore);
    });

    // 提交审核
    $("#submitForm").click(function (e) {
        e.preventDefault();
        var formData = $("#academicForm").serialize();
        $.post('/stuInfoSystem/uploadAcademic', formData, function (data) {
            if ("ok" === data) {
                $("#failedNum").attr("disabled","disabled");
                $("#bastScore").attr("disabled","disabled");
                $(".notSub").removeClass("badge-secondary");
                $(".notSub").removeClass("badge-danger");
                $(".notSub").addClass("badge-info");
                $(".notSub").html("待审核");
                // 禁用提交按钮
                $("#submitForm").attr("disabled","disabled");
                // 唤醒修改按钮
                $(".reEdit").removeAttr("disabled");
                // 删除驳回提示信息
                $("#msg").remove();
                layer.msg('提交成功！', {icon: 6});
            }else {
                layer.msg('提交失败！', {icon: 5, time: 700});
            }
        }, 'text');
    });

    // 重新编辑
    $(".reEdit").click(function (e) {
        e.preventDefault();
        // 开放提交按钮及输入按钮
        $("#submitForm").removeAttr("disabled");
        $("#bastScore").removeAttr("disabled");
        $("#failedNum").removeAttr("disabled");
        // 禁用修改按钮
        $(".reEdit").attr("disabled","disabled");
        $(".notSub").removeClass("badge-info");
        $(".notSub").removeClass("badge-danger");
        $(".notSub").addClass("badge-secondary");
        $(".notSub").html("未提交");
    });


</script>
</body>
</html>